#定义欢迎界面
def ATM():
#欢迎界面
  print("="*14,"欢迎使用自助存取款机","="*14,"\n")
#用户列表信息
user_list = [{"name":"张三","balance":100,"password":"1234567","numbers":"9876543"},
{"name":"李四","balance":900,"password":"2345678","numbers":"8765432"},
{"name":"王五","balance":300,"password":"3456789","numbers":"7654321"}]
#定义验证银行卡号与密码匹配的函数
def check(user_name,user_password):
 #验证银行卡号与密码匹配的函数
  for i in range(len(user_list)):
    if user_name == user_list[i]["numbers"] and user_password == user_list[i]["password"]:
      return i #银行卡号与密码匹配则返回该用户在ATM系统内的ID值，否则返回None值
#定义用户登录成功后操作界面的函数
def interface():
#用户登录成功后操作界面的函数
  print("="*14,"用户操作界面","="*14,"\n")
  print("{0:2} {1:12} {2:12}".format(" ","1. 查询","2. 取款"),"\n")
  print("{0:2} {1:12} {2:12}".format(" ","3. 存款","4. 退出"),"\n")
  print("="*42,"\n")
#定义用户查询信息的函数
def inquire(user_id):
#用户查询信息的函数
  print("="*14,"账号查询界面","="*14,"\n")
  print("|{0:<4}|{1:<18}|{2:<9}|\n".format("账户名","卡号","余额"))
  print("|{0:<5}|{1:<20}|{2:<11}|\n".format(user_list[user_id]["name"],user_list[user_id]["numbers"],user_list[user_id]["balance"]))
#定义用户取款的函数
def withdrawal(amount):
#用户取款的函数
  i = user_list[user_id]["balance"]-int(amount)
  if i>=0:
    user_list[user_id]["balance"]-=int(amount)
  else:
    print("账户余额不足\n")
#定义用户存款的函数
def deposit(amount):
#用户存款的函数
  user_list[user_id]["balance"]+=int(amount)
#用户登录界面，输入银行卡号和密码
while True:
  ATM()
  user_name = input("请输入您的银行卡卡号：")
  print("")
  user_password = input("请输入您的银行卡密码：")
  print("")
  user_id = check(user_name,user_password)#验证银行卡号与密码是否匹配
  if user_id != None:
    print("登录成功\n")
    while True:
      interface()
      key_word = input("请输入操作选项：")
      print("")
      if key_word == "1":
        inquire(user_id)
        input("按回车键返回上一级目录:")
        print("")
      elif key_word == "2":
        print("="*14,"账号取款界面","="*14,"\n")
        amount = input("请输入取款金额：")
        print("")
        withdrawal(amount)
        inquire(user_id)
        input("按回车键返回上一级目录:")
        print("")
      elif key_word == "3":
        print("="*14,"账号存款界面","="*14,"\n")
        amount = input("请输入存款金额：")
        print("")
        deposit(amount)
        inquire(user_id)
        input("按回车键返回上一级目录:")
        print("")
      elif key_word == "4":
        print("="*14,"欢迎下次光临","="*14,"\n")
        break
      else:
        print("="*14,"无法识别指令！","="*14,"\n")
  else:      
      print("用户名或密码错误，请重新输入！\n")